package com.itheima.mall.controller;


import com.itheima.mall.pojo.Brand;
import com.itheima.mall.service.PmsBrandService;
import com.itheima.mall.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/brand")
public class PmsBrandController {

    @Autowired
    private PmsBrandService pmsBrandService;

    /**
     * 添加品牌
     * @param pmsBrand
     * @return
     */
    @PostMapping("/create")
    public ResponseEntity create(@RequestBody Brand pmsBrand){
        pmsBrandService.create(pmsBrand);
        return ResponseEntity.ok("");
    }

    /**
     * 通过id删除标签
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    public ResponseEntity deleteById(@PathVariable("id") Integer id){
        pmsBrandService.deleteById(id);
        return ResponseEntity.ok("");
    }

    /**
     * 批量删除品牌
     * @param ids
     * @return
     */
    @PostMapping("/delete/batch")
    public ResponseEntity deleteByIds(@RequestParam("ids") Integer[] ids){
        pmsBrandService.deleteByIds(ids);
        return ResponseEntity.ok("");
    }

    /**
     * 分页显示品牌信息
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity brandList(String keyword,
                                    @RequestParam(defaultValue = "1") Integer pageNum ,
                                    @RequestParam(defaultValue = "10") Integer pageSize){
     PageResult pageResult = pmsBrandService.brandList(keyword , pageNum , pageSize);
    return ResponseEntity.ok(pageResult);
    }

    /**
     * 获取所有的品牌
     * @return
     */
    @GetMapping("/listAll")
    public ResponseEntity brandListAll(){
      List<Brand> list =  pmsBrandService.brandListAll();
        return ResponseEntity.ok(list);
    }

    /**
     * 批量更新厂家制造商状态
     * @param factoryStatus
     * @param ids
     * @return
     */
    @PostMapping("/update/factoryStatus")
    public ResponseEntity updateFactoryStatusByIds(@RequestParam("factoryStatus") Integer factoryStatus ,@RequestParam("ids") Integer [] ids){
        pmsBrandService.updateFactoryStatusByIds(factoryStatus , ids);
        return ResponseEntity.ok("");
    }

    /**
     *
     批量更新显示状态
     * @param ids
     * @param showStatus
     * @return
     */
    @PostMapping("/update/showStatus")
    public ResponseEntity updateShowStatus(@RequestParam("ids") Integer[] ids ,
                                           @RequestParam("showStatus") Integer showStatus){
        pmsBrandService.updateShowStatus(ids , showStatus);
        return ResponseEntity.ok("");
    }

    @PostMapping("/update/{id}")
    public ResponseEntity updateBrandById(@PathVariable("id") Integer id ,@RequestBody Brand pmsBrandParam){

        pmsBrandService.updateBrandById(id , pmsBrandParam);
        return ResponseEntity.ok("");
    }

    /**
     * 根据编号查询品牌信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity selectById(@PathVariable("id") Integer id){
       Brand brand = pmsBrandService.selectById(id);
        return  ResponseEntity.ok(brand);
    }

}
